﻿Public Class frmIndustryAcctSelect

    '行业类型科目的集合列表
    Private tmpList As List(Of ClsIndustryAccountType)

    '发布对象
    Private m_Broker As ClsBroker = New ClsBroker()

    Private Sub frmIndustryAcctSelect_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            '订阅事件


            '取出全部行业列表
            Dim tmpDbAccess As ClsIndustryAccountTypeDbAccess = New ClsIndustryAccountTypeDbAccess(sysAppInfoConnectionString)
            tmpList = tmpDbAccess.GetAllIndustryAccountType()
            Me.lstIndustryAcct.FullRowSelect = True '行选择，不是单元格选择
            Me.lstIndustryAcct.MultiSelect = False '不允许多行选择
            Me.lstIndustryAcct.View = View.Details
            Me.lstIndustryAcct.Items.Clear()
            Me.lstIndustryAcct.Columns.Add("代号")
            Me.lstIndustryAcct.Columns.Add("会计科目标准")
            Me.lstIndustryAcct.Columns(0).Width = 50
            Me.lstIndustryAcct.Columns(1).Width = 160

            For Each tmpCls As ClsIndustryAccountType In tmpList
                'Me.lstIndustryAcct.Items.Add(New ListViewItem(New String() {tmpCls.IndustryId.ToString, tmpCls.Industry}))
                Dim tmpItem As ListViewItem = New ListViewItem(tmpCls.IndustryId.ToString)
                tmpItem.SubItems.Add(tmpCls.Industry)
                Me.lstIndustryAcct.Items.Add(tmpItem)
                'Me.lstIndustryAcct.Items.Add(New ListViewItem(tmpCls.IndustryId.ToString))

            Next
        Catch ex As OleDb.OleDbException
            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "frmIndustryAcctSelect - Load"
        End Try
    End Sub

    Private Sub btnSelAndClose_Click(sender As Object, e As EventArgs) Handles btnSelAndClose.Click
        '引发事件
        Dim returnE As TransEventArg = New TransEventArg()

        returnE.Msg = "IndustryAcctType"

        '判断是否选择了
        If Me.lstIndustryAcct.SelectedItems.Count > 0 Then
            returnE.Obj = tmpList.Item(Me.lstIndustryAcct.SelectedItems.Item(0).Index)
            '判断窗体是否以模态打开
            If Me.Modal Then
                '窗体关闭状态置为OK
                Me.DialogResult = DialogResult.OK

            End If
        Else
            '没有选择账套，广播事件中载明没有选择
            returnE.Obj = Nothing
            If Me.Modal Then
                '窗体关闭状态置为NO
                Me.DialogResult = DialogResult.No
            End If
        End If
        '广播事件
        m_Broker.BroadCastEvent(returnE)

        '关闭自身
        Me.Close()
    End Sub
End Class